/******************************************************************************
* This file is part of is32p218 platform,
* Copyright (c) 2009 HangZhou InfoStrong CO.,LTD. All rights reserved.
* This software may only be used under the terms of a valid, current,
* end user license from InfoStrong.
* Nothing else gives you the right to use this software.   
*
* Name:   drv_sys.h
* Desc:   Driver system header file
* Author: Jerry
* Date:   2009-9-16
* Note:   
* History:
*
******************************************************************************/
#include "def.h"

#ifndef __DRV_SYS_H__
#define __DRV_SYS_H__

#ifdef __cplusplus
extern "C" {
#endif

#define CHIP_SN_LEN		6

#define LED_SYS_ID		0
#define LED_PLC_ID		1

#define min(x1,x2) ((x1<x2)? x1:x2)
#define max(x1,x2) ((x1>x2)? x1:x2)

typedef enum
{
	P00=0,
	P01,
	P02,
	P03,
#if (defined(XN5106C_EXT))
	P04,
#endif
	P05=5,
	P06,
#if (defined(XN5106C_EXT))
	P07,
	P10,
	P11,
	P12,
	P13,
	P14,
	P15,
	P16,
	P17
#endif
}IO_NUM;

#if (CHIP_ID==XN5106A)
typedef enum
{
	IO_INPUT=0,
	IO_OUTPUT
}IO_MODE;
#elif (defined(XN5106C_EXT))
typedef enum
{
	IO_OUTPUT=0,
	IO_INPUT
}IO_MODE;
#endif

typedef enum
{
	IO_LOW=0,
	IO_HIGH
}IO_VALUE;

typedef enum
{
	IO_PUR_EN,
	IO_PUR_DIS
}IO_PUR;

typedef enum
{
	IO_FUNC_SP,
	IO_FUNC_IO
}IO_FUNC;

IO_VALUE drv_sys_port0_read(IO_NUM io_num );
void drv_sys_port0_setpur(IO_NUM io_num,IO_PUR io_pur);
void drv_sys_port0_setval(IO_NUM io_num,IO_VALUE io_value);
void drv_sys_port0_setmod(IO_NUM io_num,IO_MODE io_mode);

S32 drv_sys_mem_write( U8 mode, U32 num, U32 addr, void *p_data );
S32 drv_sys_mem_read( U8 mode, U32 num, U32 addr, void *p_data );

void drv_sys_wdt_init( void );
void drv_sys_wdt_feed( void );

void drv_sys_port_init(void);
void drv_sys_led_toggle( U8 led_id );
U8 drv_sys_phase_id( void );
void drv_sys_init( void );
BOOL drv_sys_check( void );
void drv_sys_reset( void );
U8 *drv_sys_chip_sn_get( void );

void mon_get_string(char *string);
S32  mon_get_int_num(void);
void mon_printf(char *fmt,...);

#ifdef APP_AFN_EVENT_PIN_CHECK	
BOOL drv_sys_event_pin_status_read( void);
#endif

#if (defined(XN5106C_EXT))
void drv_sys_port0_setfunc(IO_NUM io_num,IO_FUNC io_func);
#endif

#ifdef __cplusplus
}
#endif

#endif /*__DRV_SYS_H__*/

